package com.ruoyi.project.edu.specialized.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.framework.web.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.edu.specialized.mapper.SpecializedMapper;
import com.ruoyi.project.edu.specialized.domain.Specialized;
import com.ruoyi.project.edu.specialized.service.ISpecializedService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 专业Service业务层处理
 * 
 * @author yueqiangu
 * @date 2021-03-01
 */
@Service
public class SpecializedServiceImpl implements ISpecializedService 
{
    @Autowired
    private SpecializedMapper specializedMapper;

    /**
     * 查询专业
     * 
     * @param id 专业ID
     * @return 专业
     */
    @Override
    public Specialized selectSpecializedById(Long id)
    {
        return specializedMapper.selectSpecializedById(id);
    }

    /**
     * 查询专业列表
     * 
     * @param specialized 专业
     * @return 专业
     */
    @Override
    public List<Specialized> selectSpecializedList(Specialized specialized)
    {
        return specializedMapper.selectSpecializedList(specialized);
    }

    /**
     * 新增专业
     * 
     * @param specialized 专业
     * @return 结果
     */
    @Override
    public int insertSpecialized(Specialized specialized)
    {
        specialized.setCreateTime(DateUtils.getNowDate());
        return specializedMapper.insertSpecialized(specialized);
    }

    /**
     * 修改专业
     * 
     * @param specialized 专业
     * @return 结果
     */
    @Override
    public int updateSpecialized(Specialized specialized)
    {
        specialized.setUpdateTime(DateUtils.getNowDate());
        return specializedMapper.updateSpecialized(specialized);
    }

    /**
     * 删除专业对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSpecializedByIds(String ids)
    {
        return specializedMapper.deleteSpecializedByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除专业信息
     * 
     * @param id 专业ID
     * @return 结果
     */
    @Override
    public int deleteSpecializedById(Long id)
    {
        return specializedMapper.deleteSpecializedById(id);
    }

    /**
     * 查询专业树列表
     * 
     * @return 所有专业信息
     */
    @Override
    public List<Ztree> selectSpecializedTree()
    {
        List<Specialized> specializedList = specializedMapper.selectSpecializedList(new Specialized());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (Specialized specialized : specializedList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(specialized.getId());
            ztree.setpId(specialized.getParentId());
            ztree.setName(specialized.getProName());
            ztree.setTitle(specialized.getProName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
